namespace Stee.CAP8.DBAccess
{

    using Microsoft.EntityFrameworkCore;
    using Stee.CAP8.Entity;
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using System.Threading;
    using System.Threading.Tasks;

    public interface IRepository<T, TContext> : IDisposable where T : BaseEntity where TContext : DbContext
    {
        void Add(T entity);
        void AddRange(params T[] entities);
        void AddRange(IEnumerable<T> entities);

        Task AddAsync(T entity, CancellationToken cancellationToken = default);
        Task AddRangeAsync(CancellationToken cancellationToken = default, params T[] entities);
        Task AddRangeAsync(IEnumerable<T> entities, CancellationToken cancellationToken = default);

        void Update(T entity);
        void UpdateRange(params T[] entities);
        void UpdateRange(IEnumerable<T> entities);
        void UpdateProperty(Guid id, string propertyName, object value);

        void Delete(T entity);
        void DeleteByID(Guid id);
        void DeleteRange(params T[] entities);
        void DeleteRange(IEnumerable<T> entities);

        T GetSingle(Expression<Func<T, bool>> condition = null);
        Task<T> GetSingleAsync(Expression<Func<T, bool>> condition = null, CancellationToken cancellationToken = default);
        T GetSingleOrDefault(Expression<Func<T, bool>> condition = null);
        Task<T> GetSingleOrDefaultAsync(Expression<Func<T, bool>> condition = null, CancellationToken cancellationToken = default);

        T GetSingle(Guid id);
        Task<T> GetSingleAsync(Guid id, CancellationToken cancellationToken = default);
        T GetSingleOrDefault(Guid id);
        Task<T> GetSingleOrDefaultAsync(Guid id, CancellationToken cancellationToken = default);

        List<T> GetList(Expression<Func<T, bool>> condition = null, IList<OrderBy> orderBy = null, int pageIndex = 1, int pageSize = 10000);
        Task<List<T>> GetListAsync(Expression<Func<T, bool>> condition = null, IList<OrderBy> orderBy = null, int pageIndex = 1, int pageSize = 10000, CancellationToken cancellationToken = default);

    }
}
